import { queryUserInfoApi } from '@/api';
import * as types from '../action-types';
import cache from '@/utils/cache';

const baseAction = {
  getUserInfo() {
    return async (dispatch) => {
      try {
        const { code, data } = await queryUserInfoApi();
        if (data) {
          cache.setCache('userInfo', data ?? {});
        }
        dispatch({
          type: types.BASE_SET_USERINFO,
          payload: code === 1 ? {} : data
        });
      } catch (_) {}
    };
  }
};

export default baseAction;
